import java.io.IOException;

// class KyoException extends IOException {
class KyoException extends RuntimeException {
    public KyoException(String message) {
        super(message);
    }

    public String toString() {
        return "KYO 自己实现的toString方法!";
    }

    /*
     * public String getMessage() {
     *     return "KYO 自己实现的getMessage方法!";
     * }
     */

    /*
     * public void printStackTrace() {
     *     System.out.printf("KYO printStackTrace: %s\n", this.toString());
     * }
     */
}

public class ExceptionTest {
    String name = "";

    public void myClone() {

    }

    //非RuntimeException必须指定抛出的异常
    // static public void test(int x) throws KyoException {
    static public void test(int x) {
        // ExceptionTest s = null;
        // int [] a = {1, 2, 3};
        /*
         * try {
         *     if (x > 10) {
         *         throw new KyoException("Test 方法数组越界!");
         *     }
         * } catch (KyoException e) {
         *     x = 16;
         * }
         */
        if (x > 10) {
            throw new KyoException("Test 抛出KYO自定义异常!");
        }

        System.out.printf("throw end code....x = %d\n", x);
        // s.name = "sdjfsdj";

        // a[3] = 230;
    }

    // static public void kyo() throws KyoException {  //非RuntimeException必须指定抛出异常
    static public void kyo() {   //RuntimeException可以不用指定抛出异常
        test(15);
        /*
         * try {
         *     test(15);
         * } catch (KyoException e) {
         *     System.out.printf("kyo把异常处理掉了...\n");
         * }
         */
    }

    static public void main(String [] args) {
        try {
            kyo();
            System.out.printf("正常代码块....!\n");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.printf("下标越界!\n");
        } catch (NullPointerException e) {
            System.out.printf("访问空指针...!\n");
            e.printStackTrace();
        } catch (Exception e) {
            System.out.printf("getMessage: %s\n", e.getMessage());
            System.out.printf("toString: %s\n", e.toString());
            e.printStackTrace();
            System.out.printf("捕捉异常后要执行代码块...!\n");
            return;   //退出main方法，但也会执行finally的代码块
        } finally {
            System.out.printf("不管什么情况都会执行代码块...!\n");
        }

        System.out.printf("main run...!\n");
    }
}
